#include <rtthread.h>
#include "base.h" 
#include "rtconfig.h"
#include "rtdef.h"

rt_timer_t led_timer;
// 回调函数
static void led_timer_cb(void *parameter) {
    RT_UNUSED(parameter);
    led_toggle(LED0);  // 切换LED 状态

    static int count;
    if (++count == 20) {
        // 可以关闭
        rt_timer_stop(led_timer);
    }
}

struct rt_timer oneshort_timer;

static void oneshort_timer_cb (void * parameter) {
    RT_UNUSED(parameter);

    led_toggle(LED1);

    // 可以重启
    rt_timer_start(&oneshort_timer);
}

int main (void) {
    hardware_init();

    // 创建一个周期性定时器（1000ms）
    led_timer = rt_timer_create("led_t",
                                led_timer_cb,
                                (void *)20,
                                rt_tick_from_millisecond(500),  // RT_TICK_PER_SECOND, 
                                RT_TIMER_FLAG_PERIODIC);

    if (led_timer != RT_NULL) {
        rt_timer_start(led_timer);  // 启动定时器
    }

    rt_timer_init(&oneshort_timer, "oneshort",
        oneshort_timer_cb, RT_NULL, 3*RT_TICK_PER_SECOND,   // 3秒
        RT_TIMER_FLAG_ONE_SHOT);    
    rt_timer_start(&oneshort_timer);

    return 0;
}